package com.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biz.TUserinfoBIZ;
import com.dao.TUserinfoDAO;
import com.entity.TUserinfo;
import com.util.Coder;

@SuppressWarnings("rawtypes")
@Service
@Transactional
public class TUserinfoBIZImpl implements TUserinfoBIZ {
	private TUserinfoDAO tUserinfoDAO;

	@Resource
	public void settUserinfoDAO(TUserinfoDAO tUserinfoDAO) {
		this.tUserinfoDAO = tUserinfoDAO;
	}

	public void save(TUserinfo transientInstance) {
		tUserinfoDAO.save(transientInstance);
	}

	public void delete(TUserinfo persistentInstance) {
		tUserinfoDAO.delete(persistentInstance);
	}

	public TUserinfo findById(String id) {

		return tUserinfoDAO.findById(id);
	}

	public List findByExample(TUserinfo instance) {

		return tUserinfoDAO.findByExample(instance);
	}

	public List findByProperty(String propertyName, Object value) {

		return tUserinfoDAO.findByProperty(propertyName, value);
	}

	public List findByName(Object name) {

		return tUserinfoDAO.findByName(name);
	}

	public List findByAddress(Object address) {

		return tUserinfoDAO.findByAddress(address);
	}

	public List findByTelephone(Object telephone) {

		return tUserinfoDAO.findByTelephone(telephone);
	}

	public List findByGender(Object gender) {

		return tUserinfoDAO.findByGender(gender);
	}

	public List findByNickname(Object nickname) {

		return tUserinfoDAO.findByNickname(nickname);
	}

	public List findByPsw(Object psw) {

		return tUserinfoDAO.findByPsw(psw);
	}

	public List findByState(Object state) {

		return tUserinfoDAO.findByState(state);
	}

	public List findByMobile(Object mobile) {

		return tUserinfoDAO.findByMobile(mobile);
	}

	public List findByFax(Object fax) {

		return tUserinfoDAO.findByFax(fax);
	}

	public List findAll() {

		return tUserinfoDAO.findAll();
	}

	public TUserinfo merge(TUserinfo detachedInstance) {

		return tUserinfoDAO.merge(detachedInstance);
	}

	public void attachDirty(TUserinfo instance) {
		tUserinfoDAO.attachDirty(instance);
	}

	public void attachClean(TUserinfo instance) {
		tUserinfoDAO.attachClean(instance);
	}
	
	public TUserinfo doLogin(TUserinfo tUserInfo){
		TUserinfo tmp =null;
		try{
			List temp = tUserinfoDAO.findByNickname(tUserInfo.getNickname());
			if(temp.size()>=1){
				TUserinfo tmp1 = (TUserinfo) temp.get(0);
				if(tmp1.getPsw().equals(Coder.pwdEncryption(tUserInfo.getPsw()))){
					return tmp1;
				}
			}else{
				temp = tUserinfoDAO.findByName(tUserInfo.getName());
				if(temp.size()>=1){
					TUserinfo tmp1 = (TUserinfo) temp.get(0);
					if(tmp1.getPsw().equals(Coder.pwdEncryption(tUserInfo.getPsw()))){
						return tmp1;
					}
				}else{
					temp = tUserinfoDAO.findByMobile(tUserInfo.getMobile());
					if(temp.size()>=1){
						TUserinfo tmp1 = (TUserinfo) temp.get(0);
						if(tmp1.getPsw().equals(Coder.pwdEncryption(tUserInfo.getPsw()))){
							return tmp1;
						}
					}
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return tmp;
	}
}
